package com.mail.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mail.dubbo.mapper.CmsSubjectMapper;
import com.mail.model.db.CmsSubject;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author 吕永乐
 * @date 2022/06/22 21:19
 **/
@DubboService
public class CmsSubjectApiImpl implements CmsSubjectApi{

	@Autowired
	private CmsSubjectMapper cmsSubjectMapper;

	/**
	 * 获取全部商品专题
	 *
	 * @return
	 */
	@Override
	public List<CmsSubject> getAll() {
		return cmsSubjectMapper.getAll();
	}

	/**
	 * 根据专题名称分页获取商品专题
	 *
	 * @param pageNum
	 * @param pageSize
	 * @param keyword
	 * @return
	 */
	@Override
	public Page<CmsSubject> getListByPage(Long pageNum, Long pageSize, String keyword) {
		Page<CmsSubject> page = new Page<>(pageNum, pageSize);
		LambdaQueryWrapper<CmsSubject> wrapper = new LambdaQueryWrapper<>();
		wrapper.like(StringUtils.isNotEmpty(keyword), CmsSubject::getCategoryName, keyword);
		return cmsSubjectMapper.selectPage(page, wrapper);
	}
}
